package com.zgkj.Zip.tools;
import java.io.File;
import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.ParseException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;


public class Uf1 {

	public void SubmitPost(String url, String file36Path) {

        HttpClient httpclient = new DefaultHttpClient();
        try {
        	System.out.println(url);

            HttpPost httppost = new HttpPost(url);
            FileBody file36 = new FileBody(new File(file36Path));

            MultipartEntity reqEntity = new MultipartEntity();

            reqEntity.addPart("file36", file36);// file36为请求后台的File upload;属性

            httppost.setEntity(reqEntity);

            HttpResponse response = httpclient.execute(httppost);

            int statusCode = response.getStatusLine().getStatusCode();
            System.out.println(statusCode);
            if (statusCode == HttpStatus.SC_OK) {

                System.out.println("服务器正常响应.....");

                HttpEntity resEntity = response.getEntity();

                System.out.println(EntityUtils.toString(resEntity));// httpclient自带的工具类读取返回数据

                System.out.println(resEntity.getContent());//这里是服务端的返回值

                EntityUtils.consume(resEntity);
            }

        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                httpclient.getConnectionManager().shutdown();
            } catch (Exception ignore) {

            }
        }
	}
	public static void main(String[] args) {
		Uf1 Uf1 = new Uf1();
		Uf1.SubmitPost("http://localhost:8888/lf/api/entra_file", "d:/GA000125257394_2001031.xml");

	}
}
